#!/usr/bin/env python
#-*-coding:utf-8-*-


from pymongo import MongoClient
import config


class DB(object):
    def __init__(self, ):
        self.conn = MongoClient(config.MONGO_HOST, config.MONGO_PORT)
        self.db = self.conn[config.FILM_DB]
        self.film_coll = self.db[config.FILM_COLL]


    def insert_film(self, films):
        self.insert_many(self.film_coll, films)


    def insert_many(self, coll, data_list):
        # coll.insert_many(data_list)
        for film in data_list:
            coll.update_one({"id":film["id"]}, {"$set":film}, upsert=True)
